<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>生成代码</title>
    <link rel="stylesheet" type="text/css" href="easyui/themes/gray/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css"/>
    <script src="easyui/jquery.min.js"></script>
    <script src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#organizationtab").datagrid({
                url: '/table/list',
                fit: true,
                fitColumns: true,
                pagination: true,
                pageList: [5, 10, 15],
                columns: [[
                    {field: 'id', checkbox: true},
                    {field: 'tableComment', title: '注释',width: 5},
                    {field: 'tableName', title: '表名',width:5},
                    {field: 'createTime', title: '创建时间',width:25}
                ]], toolbar: '#toolbardiv'
            });

            $("#addorganization").dialog({
                width: 300,
                height: 200,
                title: "添加组织",
                closed: true,
                modal: true
            });

            $("#generatorBtn").click(function () {
                var selectRows = $("#organizationtab").datagrid("getSelections");
                if(selectRows.length != 1){
                    $.messager.alert("提示","请选择一行进行代码生成！！！");
                    return;
                }
                $.post("/generatorCode", {
                    "tableName": selectRows[0].tableName,
                    "template": $("[name=template]").val()
                }, function (data) {
                    var code = JSON.stringify(data.code).replace(/\\/g,"").replace(/^"/,"").replace(/"$/,"");
                   $("#codediv").html(code);
                })
            });

        });
    </script>
</head>
<body class="easyui-layout">
    <div data-options="region:'center',title:'center title'" style="padding:5px;background:#eee;"></div>
    <div data-options="region:'east',title:'代码',split:true" style="width:50%">
        <div id="codediv">xxx</div>
    </div>
<table id="organizationtab" border="1">
    <div id="toolbardiv">
        <select class="easyui-combobox" name="template" style="width:200px;">
            <option value="Entity.java">Entity.java</option>
            <option value="Controller.java">Controller.java</option>
            <option value="Service.java">Service.java</option>
            <option value="Dao.java">Dao.java</option>
            <option value="Dao.xml">Dao.xml</option>
            <option value="CRUD.sql">CRUD.sql</option>
        </select>
        <a href="#" id="generatorBtn" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">生成代码</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true">下载代码</a>
    </div>
</table>
</body>
</html>